package com.voxel.sense.infomsg.widget;

import com.example.com.common.utils.L;
import com.example.com.common.widget.diffui.DiffUiDataCallBack;
import com.voxel.sense.infomsg.data.bean.MultiItemBean;
import com.voxel.sense.infomsg.data.bean.RealCharBean;
import com.voxel.sense.infomsg.data.bean.RealDataBean;

import java.util.List;

/**
 * Created by ChenYiYao on 2018/2/28.
 */

public class SourceCharDiffUtilsCallBack extends DiffUiDataCallBack {
    public SourceCharDiffUtilsCallBack(List oldList, List newList) {
        super(oldList, newList);
    }

    public SourceCharDiffUtilsCallBack() {
        super();
    }

    @Override
    public int getOldListSize() {
        return mOldList.size();
    }

    @Override
    public int getNewListSize() {
        return mNewList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        MultiItemBean beanOld = (MultiItemBean) mOldList.get(oldItemPosition);
        MultiItemBean beanNew = (MultiItemBean) mNewList.get(newItemPosition);
        //判断是否相同类型
        return beanNew.getType() == beanOld.getType();
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        MultiItemBean beanOld = (MultiItemBean) mOldList.get(oldItemPosition);
        MultiItemBean beanNew = (MultiItemBean) mNewList.get(newItemPosition);
        Object oblData = beanOld.getData();
        Object newData = beanNew.getData();
        //判断内容是否相同
        //然后再交由data判断
        if (oblData instanceof RealCharBean
                && newData instanceof RealCharBean) {

            RealCharBean old = (RealCharBean) oblData;
            RealCharBean newbean = (RealCharBean) newData;
            return newbean.isSame(old) && newbean.isDataContentSame(old);
        } else if (oblData instanceof RealDataBean
                && newData instanceof RealDataBean) {

            RealDataBean old1 = (RealDataBean) oblData;
            RealDataBean newB = (RealDataBean) newData;
            L.d("-----------------RealDataBean");
            return newB.isSame(old1) && newB.isDataContentSame(old1);
        } else if (oblData instanceof List || newData instanceof List) {
            L.d("----------------oblData instanceof List");
        }

        return false;
    }

}
